1 <?php
2     
3     session_start();
4     require
"admin/includes/functions.php";
5     require
"admin/includes/db.php";
6     
7     $msg =
"";
8     
9     
if($_SERVER['REQUEST_METHOD'] == 'POST') {
10         
11         
if(isset($_POST['submit'])) {
12             
13             $guest = preg_replace(
"#[^0-9]#", "", $_POST['guest']);
14             $email = filter_var($_POST[
'email'], FILTER_VALIDATE_EMAIL);
15             $phone = preg_replace(
"#[^0-9]#", "", $_POST['phone']);
16             $date_res = htmlentities($_POST[
'date_res'], ENT_QUOTES, 'UTF-8');
17             $time = htmlentities($_POST[
'time'], ENT_QUOTES, 'UTF-8');
18             $suggestions = htmlentities($_POST[
'suggestions'], ENT_QUOTES, 'UTF-8');
19             
20             
if($guest != "" && $email && $phone != "" && $date_res != "" && $time != "" && $suggestions != "") {
21                 
22                 
//Check for remaining table space;
23                 $table_array = array();
24                 $mtime = strftime(
"%H", time());
25                 $mdate = strftime(
"%Y-%m-%d", time());
26                 $get_table_count = $db->query(
"SELECT global_amt FROM Globals");
27                 $row_count = $get_table_count->fetch_assoc();
28                 $table_count = $row_count[
'global_amt'];
29                 $fetch = $db->query(
"SELECT * FROM reservation");
30                 
if($fetch->num_rows) {
31                     
while($row_fetch = $fetch->fetch_assoc()) {
32                         
if(($row_fetch['date_res'] >= $mdate) && ($row_fetch['time'] >= $mtime)) {
33                             $table_array[] = $row_fetch[
'reserve_id'];
34                         }
35                     }
36                 }
37                 echo(count($table_array));
38                 
if(count($table_array) < $table_count) {
39                     $check = $db->query(
"SELECT * FROM reservation WHERE no_of_guest='".$guest."' AND email='".$email."' AND phone='".$phone."' AND date_res='".$date_res."' AND time='".$time."' LIMIT 1");
40                     
41                     
if($check->num_rows) {
42                         
43                         $msg =
"<p style='padding: 15px; color: red; background: #ffeeee; font-weight: bold; font-size: 13px; border-radius: 4px; text-align: center;'>You have already placed a reservation with the same information</p>";
44                         
45                     }
else{
46                         
47                         $insert = $db->query(
"INSERT INTO reservation(no_of_guest, email, phone, date_res, time, suggestions) VALUES('".$guest."', '".$email."', '".$phone."', '".$date_res."', '".$time."', '".$suggestions."')");
48                         
49                         
if($insert) {
50                             
51                             $ins_id = $db->insert_id;
52                             
53                             $reserve_code =
"UNIQUE_$ins_id".substr($phone, 3, 8);
54                             
55                             $msg =
"<p style='padding: 15px; color: green; background: #eeffee; font-weight: bold; font-size: 13px; border-radius: 4px; text-align: center;'>Đặt bàn thành công. Mã đặt bàn $reserve_code. Trà sữa Milk Tea chúc bạn có nhiều giây phút vui vẻ bên bạn bè!</p>";
56                             
57                         }
else{
58                             
59                             $msg =
"<p style='padding: 15px; color: red; background: #ffeeee; font-weight: bold; font-size: 13px; border-radius: 4px; text-align: center;'>Không thể đặt bàn. Vui lòng thử lại</p>";
60                             
61                         }
62                         
63                     }
64                 }
else{
65                     
66                     $msg =
"<p style='padding: 15px; color: red; background: #ffeeee; font-weight: bold; font-size: 13px; border-radius: 4px; text-align: center;'>Không có chỗ trống. Vui lòng kiểm tra lại sau một giờ</p>";
67                     
68                 }
69                 
70             }
else{
71                 
72                 $msg =
"<p style='padding: 15px; color: red; background: #ffeeee; font-weight: bold; font-size: 13px; border-radius: 4px; text-align: center;'>Để đặt bàn hãy điền đầy đủ thông tin ở trên. Xin cảm ơn</p>";
73                 
74                 
//print_r($_POST);
75                 
76             }
77             
78         }
79         
80     }
81     
82 ?>
83
84 <!Doctype html>
85
86 <html lang=
"en">
87 <meta charset=
"utf-8" />
88 <meta http-equiv=
"X-UA-Compatible" content="IE=edge,chrome=1" />
89 <meta name=
"viewport" content="width=device-width, initial-scale=1.0" />
90
91 <meta name=
"description" content="" />
92
93 <meta name=
"keywords" content="" />
94
95 <head>
96     
97 <title>Đặt bàn - Trà sữa hương vị ngon</title>
98
99 <link rel=
"stylesheet" href="css/main.css" />
100
101 <script src=
"js/jquery.min.js" ></script>
102
103 <script src=
"js/myscript.js"></script>
104     
105 </head>
106
107 <body>
108     
109 <?php require
"includes/header.php"; ?>
110
111 <div
class="parallax" onclick="remove_class()">
112     
113     <div
class="parallax_head">
114         
115         <h2>Trà sữa hương vị ngon</h2>
116         <h3><!--Table Space--></h3>
117         
118     </div>
119     
120 </div>
121
122 <div
class="content" onclick="remove_class()">
123
124
125     
126     <div
class="inner_content">
127
128 <?php
129                     $result =
"";
130     $pagenum =
"";
131     $per_page =
10;
132         
133         $count = $db->query(
"SELECT * FROM food");
134         
135         $pages = ceil((mysqli_num_rows($count)) / $per_page);
136         
137         
if(isset($_GET['page'])) {
138             
139             $page = $_GET[
'page'];
140             
141         }
else{
142             
143             $page =
1;
144             
145         }
146                         
147         $start = ($page -
1) * $per_page;
148         
149         $cat = $db->query(
"SELECT * FROM food LIMIT $start, $per_page");
150         
151         
if($cat->num_rows) {
152             
153             $result =
"<table class='table table-hover table-striped'>
154                         <thead>
155                             <th>Thực đơn</th>
156                             <th></th>
157                             <th>Giá</th>
158                         </thead>
159                         <tbody>"
;
160             
161             $x =
1;
162             
163             
while($row = $cat->fetch_assoc()) {
164                 
165                 $id = $row[
'id'];
166                 $foodName = $row[
'food_name'];
167                 $foodCat = $row[
'food_category'];
168                 $foodPrice = $row[
'food_price'];
169                 $foodDesc = $row[
'food_description'];
170                 
171                 
172                 $result .=
"<tr>
173                                 <td><img src='image/FoodPics/"
.$row['id'].".jpg' width='80px' height='80px' /> </td>
174                                 <td><span
class='clickchon'>$foodName </span></td>
175                                 <td>$foodPrice</td>
176                             </tr>"
;
177                                                                 
178                                     
179                 $x++;
180             }
181             
182             $result .=
"</tbody>
183                         </table>"
;
184             
185         }
else{
186             
187             $result =
"<p style='color:red; padding: 10px; background: #ffeeee;'>No records available in the database yet</p>";
188             
189         }
190                     ?>
191 <!-- end danh sach dat ban -->
192         
193         <form method=
"post" action="<?php echo $_SERVER['PHP_SELF']; ?>" class="hr_book_form">
194             
195             <h2
class="form_head"><span class="book_icon">Đặt Bàn</span></h2>
196             <p
class="form_slg">Trà Sữa Milk Tea hương vị thơm - chuẩn vị ngon</p>
197             
198             <?php echo
"<br/>".$msg; ?>
199             
200             <div
class="left">
201
202
203                 <div
class="box">
204                     <div
class="box1" onClick="reply_click(this.id)" id="1">
205                         <img
class="imgb" src="image/icons/1887799-200.png" alt="image/icons/1887799-200.png"/>
206
207                         <p>Bàn
1</p>
208                     </div><!-- box item -->
209
210                     <div
class="box1" onClick="reply_click(this.id)" id="2">
211                         <img
class="imgb" src="image/icons/1887799-200.png" alt="image/icons/1887799-200.png"/>
212
213                         <p>Bàn
2</p>
214                     </div><!-- box item -->
215
216                     <div
class="box1" onClick="reply_click(this.id)" id="3">
217                         <img
class="imgb" src="image/icons/1887799-200.png" alt="image/icons/1887799-200.png"/>
218
219                         <p>Bàn
3</p>
220                     </div><!-- box item -->
221
222                     <div
class="box1" onClick="reply_click(this.id)" id="4">
223                         <img
class="imgb" src="image/icons/1887799-200.png" alt="image/icons/1887799-200.png"/>
224
225                         <p>Bàn
4</p>
226                     </div><!-- box item -->
227
228                     <div
class="box1 boxcuoi" onClick="reply_click(this.id)" id="5">
229                         <img
class="imgb" src="image/icons/1887799-200.png" alt="image/icons/1887799-200.png"/>
230
231                         <p>Bàn
5</p>
232                     </div><!-- box item -->
233
234                     <div
class="box1" onClick="reply_click(this.id)" id="6">
235                         <img
class="imgb" src="image/icons/1887799-200.png" alt="image/icons/1887799-200.png"/>
236
237                         <p>Bàn
6</p>
238                     </div><!-- box item -->
239
240                     <div
class="box1" onClick="reply_click(this.id)" id="7">
241                         <img
class="imgb" src="image/icons/1887799-200.png" alt="image/icons/1887799-200.png"/>
242
243                         <p>Bàn
7</p>
244                     </div><!-- box item -->
245
246                     <div
class="box1" onClick="reply_click(this.id)" id="8">
247                         <img
class="imgb" src="image/icons/1887799-200.png" alt="image/icons/1887799-200.png"/>
248
249                         <p>Bàn
8</p>
250                     </div><!-- box item -->
251
252                     <div
class="box1" onClick="reply_click(this.id)" id="9">
253                         <img
class="imgb" src="image/icons/1887799-200.png" alt="image/icons/1887799-200.png"/>
254
255                         <p>Bàn
9</p>
256                     </div><!-- box item -->
257
258                     <div
class="box1 boxcuoi" onClick="reply_click(this.id)" id="10">
259                         <img
class="imgb" src="image/icons/1887799-200.png" alt="image/icons/1887799-200.png"/>
260
261                         <p>Bàn
10</p>
262                     </div><!-- box item -->
263
264                 </div><!-- end box -->
265
266                 <div
class="clearfix"></div>
267
268                 
269                 <div
class="form_group" style="display:none">
270                      
271                      <label>Chọn bàn số</label>
272                     <input type=
"number" placeholder="" min="1" name="guest" id="guest" required>
273                     
274                 </div>
275                 
276                 <div
class="form_group">
277                     
278                     <label>Email</label>
279                     <input type=
"email" name="email" placeholder="Địa chỉ Email" required>
280                     
281                 </div>
282                 
283                 <div
class="form_group">
284                     
285                     <label>Di động</label>
286                     <input type=
"text" name="phone" placeholder="Số điện thoại của bạn" required>
287                     
288                 </div>
289                 
290                 <div
class="form_group">
291                     
292                     <label>Đặt Ngày</label>
293                     <input type=
"date" name="date_res" placeholder="Select date for booking" required>
294                     
295                 </div>
296                 
297                 <div
class="form_group">
298                     
299                     <label>Đặt Giờ</label>
300                     <input type=
"time" name="time" placeholder="Select time for booking" required>
301                     
302                 </div>
303                 
304                 
305             </div>
306             
307             <div
class="left">
308
309                 <div
class="boxthucdon">
310                     
311                     <div
class="content table-responsive table-full-width">
312                                 
313                                 <?php echo $result; ?>
314                                 
315                                 <p style=
"padding: 0px 20px;"><?php if($pages >= 1 && $page <= $pages) {
316                                     
for($i = 1; $i <= $pages; $i++) {
317                                         echo ($i == $page) ?
"<a href='reservation.php?page=".$i."' style='margin-left:5px; font-weight: bold; text-decoration: none; color: #FF5722;' >$i</a> " : " <a href='reservation.php?page=".$i."' class='btn'>$i</a> ";
318                                     }
319                                 } ?></p>
320
321                             </div>
322                 </div><!-- end box-thucdon-->
323                 
324                 <div
class="form_group" style="display:none;">
325                     
326                     <label>Gợi ý <small><b>(E.g Đặt bàn Vip, Đặt bàn lãng mạng hẹn hò...)</b></small></label>
327                     <textarea id=
"suggestions" name="suggestions" placeholder="Viết một vài ý tưởng của bạn ở đây nhé!" required></textarea>
328                     
329                     <div style=
"display:none" class="tieude"></div>
330                 </div>
331                 
332                 <div
class="form_group">
333                     
334                     <input type=
"submit" class="submit" name="submit" value="ĐẶT BÀN" />
335                     
336                 </div>
337                 
338             </div>
339             
340             <p
class="clear"></p>
341             
342         </form>
343         
344     </div>
345     
346 </div>
347
348 <div
class="content" onclick="remove_class()">
349     
350     <div
class="inner_content">
351     
352         <div
class="contact">
353             
354             <div
class="left">
355                 
356                 <h3>Địa chỉ</h3>
357                 <p>
247 Lê Trọng Thấn - Thanh Xuân</p>
358                 <p>Hà Nội</p>
359                 
360             </div>
361             
362             <div
class="left">
363                 
364                 <h3>Liên hệ</h3>
365                 <p>
0972949801</p>
366                 <p>trasuathomngon@gmail.com</p>
367                 
368             </div>
369             
370             <p
class="left"></p>
371             
372             <div
class="icon_holder">
373                 
374                 <a href=
"#"><img src="image/icons/Facebook.png" alt="image/icons/Facebook.png" /></a>
375                 <a href=
"#"><img src="image/icons/Google+.png" alt="image/icons/Google+.png" /></a>
376                 <a href=
"#"><img src="image/icons/Twitter.png" alt="image/icons/Twitter.png" /></a>
377                 
378             </div>
379             
380         </div>
381         
382     </div>
383     
384 </div>
385
386 <div
class="footer_parallax" onclick="remove_class()">
387     
388     <div
class="on_footer_parallax">
389         
390         <p>&copy; <?php echo strftime(
"%Y", time()); ?> <span></span>.Trà Sữa Hương Vị Thơm - Chuẩn Vị Ngon - Khơi Nguồn Cảm Hứng</p>
391         
392     </div>
393     
394 </div>
395
396 <script type=
"text/javascript">
397
398
399  function reply_click(clicked_id)
400 {
401     $(
'#guest').val(clicked_id);
402
403 }
404
405 $(function() {
//run when the DOM is ready
406   $(
".imgb").click(function() { //use a class, since your ID gets mangled
407     $(
'.imgb').removeClass("active");
408     $(
this).addClass("active"); //add the class to the clicked element
409   });
410
411   $(
".clickchon").click(function(){
412
413     $(
this).addClass("active2");
414
415     
var x = $(this).text();
416
417     $(
".tieude").append(x+',');
418
419     $(
"#suggestions").val($('.tieude').text());
420
421   });
422
423   
424 });
425
426
427
428 </script>
429
430 </body>
431
432 </html>


Gõ tìm kiếm nhanh...